package com.example.demo.service.impl;

import com.example.demo.domain.dto.Email;
import com.example.demo.domain.dto.User;
import com.example.demo.event.UserMailEvent;
import com.example.demo.event.UserRegisterEvent;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @Description :
 * @Author : Bruce Lee
 * @CreateTime : 2024/3/27
 */


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private ApplicationContext applicationContext;

    public void register(User user)
    {
        // 发布事件
        applicationContext.publishEvent(new UserRegisterEvent(this, user));
        System.out.println("用户注册成功");
    }

    public void sendMail(Email Email)
    {
        // 发布事件
        applicationContext.publishEvent(new UserMailEvent(this, Email));
        System.out.println("邮件发送成功");
    }

}
